package xyz.yuzegod.megawalls.classes.novice.skeleton;

import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.CollectSkill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.ItemUtils;
import xyz.yuzegod.megawalls.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class FourthSkill extends CollectSkill
{
    public FourthSkill(final Classes classes) {
        super("效率", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.3333;
            }
            case 2: {
                return 0.6667;
            }
            case 3: {
                return 1.0;
            }
            default: {
                return 0.3333;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7在挖矿或伐木时,");
            lore.add("    §7有§a" + StringUtils.percent(this.getAttribute(level)) + "§7几率获得三倍掉落。");
            return lore;
        }
        lore.add(" §8▪ §7在挖矿或伐木时,");
        lore.add("    §7有§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜");
        lore.add("    §a" + StringUtils.percent(this.getAttribute(level)) + "§7几率获得三倍掉落。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill4Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill4Level();
    }
    
    @Override
    public void onBlockBreak(final KitStatsContainer kitStats, final BlockBreakEvent e) {
        if ((ItemUtils.exceptDirt(e.getBlock())) && MegaWalls.getRandom().nextInt(100) <= this.getAttribute(kitStats.getSkill4Level()) * 100.0) {
            final Player player = e.getPlayer();
            for (final ItemStack itemStack : e.getBlock().getDrops()) {
                itemStack.setAmount(itemStack.getAmount() * 2);
                player.getWorld().dropItem(e.getBlock().getLocation(), itemStack);
            }
        }
    }
}
